package com.liuyz.thread_;

// 线程常用方法
public class ThreadMethods {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new ThreadMethod());
        thread.setName("test"); // 设置线程名称
        thread.setPriority(Thread.MIN_PRIORITY); // 设置线程优先级
        thread.start(); // 线程启动
        // threadMethod.run(); // 调用线程的run方法

        Thread.sleep(5000); // 线程休眠
        thread.interrupt(); // 让子线程中断

        // thread.yield(); // 线程礼让
        // thread.join(); // 线程插队
    }
}


class ThreadMethod implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()); // 获取线程名称
        System.out.println(Thread.currentThread().getPriority()); // 获取线程优先级
        try {
            Thread.sleep(50000); // 线程休眠
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.out.println(Thread.currentThread().getName() + " 线程被中断了");
        }
    }
}
